package GUI_creator;

import GUI.*;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;

import logicCreator.Creator;


public class BoardPanelCreator extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Creator creator;
	public BoardPanelCreator(Creator creator,CellCreator[][] board) {
		this.creator = creator;
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0};
		gridBagLayout.rowHeights = new int[]{0};
		gridBagLayout.columnWeights = new double[]{Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{Double.MIN_VALUE};
		setLayout(gridBagLayout);

		for(int i =0; i< creator.getMat().length;i++)
		{
			for(int j = 0 ; j< creator.getMat().length;j++){

				CellCreator cellCreator = new CellCreator();
				cellCreator.setBackground(Color.white);
				GridBagConstraints gbc_lblCell = new GridBagConstraints();
				gbc_lblCell.insets = new Insets(0, 0, 0, 0);
				gbc_lblCell.gridx = i;
				gbc_lblCell.gridy = j;
				add(cellCreator, gbc_lblCell);

				board[i][j] = cellCreator;
				cellCreator.addMouseListener(new MouseAdapter() {
					@Override
					public void mousePressed(MouseEvent e) {
						if (e.getModifiers() == MouseEvent.BUTTON1_MASK )
						{
							((CellCreator)e.getSource()).color=CreatorPanel.selectedColor;
							((JPanel)GUI.frame.getContentPane()).revalidate();
							GUI.frame.repaint();
						}
						else if(e.getModifiers() == MouseEvent.BUTTON3_MASK)
						{
							((CellCreator)e.getSource()).color= Color.WHITE;
							((JPanel)GUI.frame.getContentPane()).revalidate();
							GUI.frame.repaint();
						}
							

					}
				});

			}
		}


	}

}
